<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: LJQ <245369209@qq.com>
// +----------------------------------------------------------------------
namespace app\duty\controller\api;
use app\common\controller\Api;
use think\response\Json;

/**
 * 记录管理
 * @package app\news
 * @author LJQ<245369209@qq.com>
 */
class Replay extends Api

{

    /**
     *  文件列表
     * @param string
     * @return Json
     */

    public function fileList($eventId=null){

        //分页参数
        if(($limit = input('limit')) && ($page = input('page'))){
            $startLimit =  ($page-1)*$limit;
            // 信息列表
            $info =collection(model('replay')->with('user')->where(array('msgType'=>2,'eventId'=>$eventId))->limit($startLimit.','.$limit)->select())->toArray();
        }else{
            //信息列表
            $info =collection(model('replay')->with('user')->where(array('msgType'=>2,'eventId'=>$eventId))->select())->toArray();
        }

        //总数
        $count = model('replay')->where(array('msgType'=>2,'eventId'=>$eventId))->count('id');
       
      
        return json(['code'=>1,'msg'=>'信息','count'=>$count,'data'=>$info]);
        
    }



    /**
     *  视频列表
     * @param string
     * @return Json
     */

    public function videoList($eventId=null){

        //分页参数
        if(($limit = input('limit')) && ($page = input('page'))){
            $startLimit =  ($page-1)*$limit;
            // 信息列表
            $info =collection(model('replay')->with('user')->where(array('msgType'=>1,'eventId'=>$eventId))->limit($startLimit.','.$limit)->select())->toArray();
        }else{
            //信息列表
            $info =collection(model('replay')->with('user')->where(array('msgType'=>1,'eventId'=>$eventId))->select())->toArray();
        }

        //总数
        $count = model('replay')->where(array('msgType'=>1,'eventId'=>$eventId))->count('id');

    	return json(['code'=>1,'msg'=>'信息','count'=>$count,'data'=>$info]);
    }




    /**
     *  图片列表
     * @param string
     * @return Json
     */

    public function photoList($eventId=null){

        //分页参数
        if(($limit = input('limit')) && ($page = input('page'))){
            $startLimit =  ($page-1)*$limit;
            // 信息列表
            $info =collection(model('replay')->with('user')->where(array('msgType'=>4,'eventId'=>$eventId))->limit($startLimit.','.$limit)->select())->toArray();
        }else{
            //信息列表
            $info =collection(model('replay')->with('user')->where(array('msgType'=>4,'eventId'=>$eventId))->select())->toArray();
        }

        //总数
        $count = model('replay')->where(array('msgType'=>4,'eventId'=>$eventId))->count('id');

   
        return json(['code'=>1,'msg'=>'信息','count'=>$count,'data'=>$info]);
    }


    /**
     *   查询文件
     * @param keyword信息名称
     * @return Json
     */
    public function searchFile($start=null,$end=null,$keyword=null){
        $where = [] ;

        if($keyword){

            $where['title'] = ['like','%'.$keyword.'%'];
        }

        if($start&&$end){
            $start=strtotime($start);
            $end=strtotime($end);

            $where['createTime'] = ['between time',[$start,$end]];
        }

        //分页参数
        if(($limit = input('limit')) && ($page = input('page'))){
            $startLimit =  ($page-1)*$limit;
            //信息列表
            $info =collection(model('news')->with('user')->where($where)->limit($startLimit.','.$limit)->select())->toArray();
        }else{
            //信息列表
            $info =collection(model('news')->with('user')->where($where)->select())->toArray();
        }
        //总数
        $count = model('news')->where($where)->count('id');

        if (empty($info) && $count == 0) {
            return json(['code'=>0,'msg'=>'没有找到信息','count'=>$count]);
        }

        if ($count > 0){
            return json(['code'=>1,'msg'=>'信息','count'=>$count,'data'=>$info]);
        }
    }


    /**
     *   查询文件
     * @param keyword信息名称
     * @return Json
     */
    public function searchVideo($start=null,$end=null,$keyword=null){
        $where = [] ;

        if($keyword){

            $where['title'] = ['like','%'.$keyword.'%'];
        }

        if($start&&$end){
            $start=strtotime($start);
            $end=strtotime($end);

            $where['createTime'] = ['between time',[$start,$end]];
        }

        //分页参数
        if(($limit = input('limit')) && ($page = input('page'))){
            $startLimit =  ($page-1)*$limit;
            //信息列表
            $info =collection(model('news')->with('user')->where($where)->limit($startLimit.','.$limit)->select())->toArray();
        }else{
            //信息列表
            $info =collection(model('news')->with('user')->where($where)->select())->toArray();
        }
        //总数
        $count = model('news')->where($where)->count('id');

        if (empty($info) && $count == 0) {
            return json(['code'=>0,'msg'=>'没有找到信息','count'=>$count]);
        }

        if ($count > 0){
            return json(['code'=>1,'msg'=>'信息','count'=>$count,'data'=>$info]);
        }
    }



    /**
     *   查询文件
     * @param keyword信息名称
     * @return Json
     */
    public function searchPhoto($start=null,$end=null,$keyword=null){
        $where = [] ;

        if($keyword){

            $where['title'] = ['like','%'.$keyword.'%'];
        }

        if($start&&$end){
            $start=strtotime($start);
            $end=strtotime($end);

            $where['createTime'] = ['between time',[$start,$end]];
        }

        //分页参数
        if(($limit = input('limit')) && ($page = input('page'))){
            $startLimit =  ($page-1)*$limit;
            //信息列表
            $info =collection(model('news')->with('user')->where($where)->limit($startLimit.','.$limit)->select())->toArray();
        }else{
            //信息列表
            $info =collection(model('news')->with('user')->where($where)->select())->toArray();
        }
        //总数
        $count = model('news')->where($where)->count('id');

        if (empty($info) && $count == 0) {
            return json(['code'=>0,'msg'=>'没有找到信息','count'=>$count]);
        }

        if ($count > 0){
            return json(['code'=>1,'msg'=>'信息','count'=>$count,'data'=>$info]);
        }
    }




}